<template>
	<div class="animate-positiona">
		<div class="new-modal-title" style="font-size: 17px; position: absolute; width: 100%; z-index: 999;">
			<i class="ion-chevron-left return" @click="genderDelete()"></i>
			{{title}}			
			<i class="right-submit" @click="genderSubmit()">确定</i>
		</div>		
		<div class="page has-navbar has-tabbar" >
			<div class="page-content padding-top" style="margin-bottom: 0"></div>
		</div>
		<div class="car-editor" style="padding-top: 44px;">
			<div class="reserve">
				<item>
					<div class="car-enitor-tr active">
						<div class="car-editor-name">客户名称</div>
						<div class="car-editor-input"><input type="text" v-model="res.customerName" max="99999" required="required" placeholder="客户名称" /></div>
					</div>
				</item>
				<item>
					<div class="car-enitor-tr active">
						<div class="car-editor-name">客户电话</div>
						<div class="car-editor-input"><input type="text" v-model="res.customerPhone" required="required" pattern="/^(\d{11})/" placeholder="11位客户电话" /></div>
					</div>
				</item>
			</div>
		</div>
	</div>
					
</template>

<script>
	export default{
		data(){
			return{
				title:'编辑客户',
				titleList:[
					{
						id:1,
						name:'编辑客户'
					},
					{
						id:2,
						name:'新增客户'
					},
				],
				res:{},
			}
		},
		created(){
			if(this.params.phoneRecordId){
				this.res = Object.create(this.params)
				this.title = this.titleList[0].name
			}else{
				this.title = this.titleList[1].name
			}
		},
		methods:{
			setData(){
				if(this.params.phoneRecordId){					
					console.log(this.res)
					axios.get(baseUrl+'/crm-web/controller/resForApp/updatePhoneRecord',{params:{
						customerName:this.res.customerName,
						customerPhone:this.res.customerPhone,
						phoneRecordId:this.res.phoneRecordId
					}}).then(res=>{
						if(res){
							setTimeout(()=>{
								$toast.show('更新成功')
								setTimeout(()=>{
									this.$emit('onsubmit',true)
								},1000)
							},400)
							
						}
					})
				}else{
					axios.get(baseUrl+'/crm-web/controller/resForApp/insertPhoneRecord',{params:{
						customerName:this.res.customerName,
						customerPhone:this.res.customerPhone,
						userId:sess.get('userSession').userId,
					}}).then(res=>{
						if(res){
							setTimeout(()=>{
								$toast.show('新增成功')
								setTimeout(()=>{
									this.$emit('onsubmit',true)
								},1000)
							},400)
						}
					})
				}
			},
			genderDelete(){
				this.$emit('onsubmit',false)
			},
			genderSubmit(){
				console.log(this.params)
				if(!this.res.customerName){
					$toast.show('请输入客户名称')
					return
				}
				if(this.res.customerPhone.length!=11){
					$toast.show('请输入正确的客户电话')
					return
				}
				this.setData()
			},
		},
		props:[
			'params'
		],
		
	}
</script>

<style>
</style>